﻿using System;
using Microsoft.Ajax.Utilities;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Xpedite.Minification.MsAjaxMinifier.Config;

/* Copyright (c) 2010 CBaxter
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), 
 * to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 
 * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 
 * IN THE SOFTWARE. 
 */

namespace Xpedite.Minification.MsAjaxMinifier.Test.Config
{
  [TestClass]
  public class ConfigSectionHandlerTest
  {
    [Ignore]
    [TestMethod]
    public void TestCanParseDefinedConfig()
    {
      var configSection = ConfigSectionHandler.Instance;

      ICssOptions actualCss = configSection.Css;
      Assert.AreEqual(true, actualCss.AllowEmbeddedAspNetBlocks);
      Assert.AreEqual(CssColor.Hex, actualCss.ColorNames);
      Assert.AreEqual(CssComment.Hacks, actualCss.CommentMode);
      Assert.AreEqual(true, actualCss.ExpandOutput);
      Assert.AreEqual("ErrorList", actualCss.IgnoreErrorList);
      Assert.AreEqual(2, actualCss.IndentSpaces);
      Assert.AreEqual(false, actualCss.MinifyExpressions);
      Assert.AreEqual(true, actualCss.TermSemicolons);

      IJavaScriptOptions actualJs = configSection.JavaScript;
      Assert.AreEqual(true, actualJs.AllowEmbeddedAspNetBlocks);
      Assert.AreEqual(false, actualJs.CollapseToLiteral);
      Assert.AreEqual(true, actualJs.CombineDuplicateLiterals);
      Assert.AreEqual("Debug", actualJs.DebugLookupList);
      Assert.AreEqual(false, actualJs.EvalLiteralExpressions);
      Assert.AreEqual(EvalTreatment.MakeAllSafe, actualJs.EvalTreatment);
      Assert.AreEqual(true, actualJs.IgnoreConditionalCompilation);
      Assert.AreEqual("IgnoreList", actualJs.IgnoreErrorList);
      Assert.AreEqual(2, actualJs.IndentSize);
      Assert.AreEqual(false, actualJs.InlineSafeStrings);
      Assert.AreEqual("KnownList", actualJs.KnownGlobalNamesList);
      Assert.AreEqual(LocalRenaming.KeepAll, actualJs.LocalRenaming);
      Assert.AreEqual(false, actualJs.MacSafariQuirks);
      Assert.AreEqual(false, actualJs.ManualRenamesProperties);
      Assert.AreEqual(false, actualJs.MinifyCode);
      Assert.AreEqual("NoAutoList", actualJs.NoAutoRenameList);
      Assert.AreEqual(OutputMode.MultipleLines, actualJs.OutputMode);
      Assert.AreEqual("PreProcessorList", actualJs.PreprocessorDefineList);
      Assert.AreEqual(true, actualJs.PreserveFunctionNames);
      Assert.AreEqual(false, actualJs.PreserveImportantComments);
      Assert.AreEqual(false, actualJs.RemoveFunctionExpressionNames);
      Assert.AreEqual(false, actualJs.RemoveUnneededCode);
      Assert.AreEqual("RenamePairsList", actualJs.RenamePairs);
      Assert.AreEqual(false, actualJs.ReorderScopeDeclarations);
      Assert.AreEqual(false, actualJs.StripDebugStatements);
    }

    [TestMethod]
    public void TestCanParseMissingConfig()
    {
      var configSection = ConfigSectionHandler.Instance;
      var expectedCss = new CssSettings();
      var expectedJs = new CodeSettings();

      ICssOptions actualCss = configSection.Css;
      Assert.AreEqual(expectedCss.AllowEmbeddedAspNetBlocks, actualCss.AllowEmbeddedAspNetBlocks);
      Assert.AreEqual(expectedCss.ColorNames, actualCss.ColorNames);
      Assert.AreEqual(expectedCss.CommentMode, actualCss.CommentMode);
      Assert.AreEqual(expectedCss.ExpandOutput, actualCss.ExpandOutput);
      Assert.AreEqual(String.Empty, actualCss.IgnoreErrorList);
      Assert.AreEqual(expectedCss.IndentSpaces, actualCss.IndentSpaces);
      Assert.AreEqual(expectedCss.MinifyExpressions, actualCss.MinifyExpressions);
      Assert.AreEqual(expectedCss.TermSemicolons, actualCss.TermSemicolons);

      IJavaScriptOptions actualJs = configSection.JavaScript;
      Assert.AreEqual(expectedJs.AllowEmbeddedAspNetBlocks, actualJs.AllowEmbeddedAspNetBlocks);
      Assert.AreEqual(expectedJs.CollapseToLiteral, actualJs.CollapseToLiteral);
      Assert.AreEqual(expectedJs.CombineDuplicateLiterals, actualJs.CombineDuplicateLiterals);
      Assert.AreEqual(expectedJs.DebugLookupList, actualJs.DebugLookupList);
      Assert.AreEqual(expectedJs.EvalLiteralExpressions, actualJs.EvalLiteralExpressions);
      Assert.AreEqual(expectedJs.EvalTreatment, actualJs.EvalTreatment);
      Assert.AreEqual(expectedJs.IgnoreConditionalCompilation, actualJs.IgnoreConditionalCompilation);
      Assert.AreEqual(String.Empty, actualJs.IgnoreErrorList);
      Assert.AreEqual(expectedJs.IndentSize, actualJs.IndentSize);
      Assert.AreEqual(expectedJs.InlineSafeStrings, actualJs.InlineSafeStrings);
      Assert.AreEqual(String.Empty, actualJs.KnownGlobalNamesList);
      Assert.AreEqual(expectedJs.LocalRenaming, actualJs.LocalRenaming);
      Assert.AreEqual(expectedJs.MacSafariQuirks, actualJs.MacSafariQuirks);
      Assert.AreEqual(expectedJs.ManualRenamesProperties, actualJs.ManualRenamesProperties);
      Assert.AreEqual(expectedJs.MinifyCode, actualJs.MinifyCode);
      Assert.AreEqual(String.Empty, actualJs.NoAutoRenameList);
      Assert.AreEqual(expectedJs.OutputMode, actualJs.OutputMode);
      Assert.AreEqual(String.Empty, actualJs.PreprocessorDefineList);
      Assert.AreEqual(expectedJs.PreserveFunctionNames, actualJs.PreserveFunctionNames);
      Assert.AreEqual(expectedJs.PreserveImportantComments, actualJs.PreserveImportantComments);
      Assert.AreEqual(expectedJs.RemoveFunctionExpressionNames, actualJs.RemoveFunctionExpressionNames);
      Assert.AreEqual(expectedJs.RemoveUnneededCode, actualJs.RemoveUnneededCode);
      Assert.AreEqual(String.Empty, actualJs.RenamePairs);
      Assert.AreEqual(expectedJs.ReorderScopeDeclarations, actualJs.ReorderScopeDeclarations);
      Assert.AreEqual(expectedJs.StripDebugStatements, actualJs.StripDebugStatements);
    }
  }
}
